// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import '@/style/index.scss'
import VueAMap from 'vue-amap'
import ECharts from 'vue-echarts'
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueAMap)
Vue.component('chart', ECharts)
/* eslint-disable no-new */
VueAMap.initAMapApiLoader({
  // 高德的key
  key: '6a204f2b675f32f8849ec4b6b7c21e5c',
  // 插件集合
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  // 高德 sdk 版本，默认为 1.4.4
  v: '1.4.4'
})

// 守卫导航
router.beforeEach((to, from, next) => {
  let mytoken = localStorage.getItem('mytoken') || ''
  // console.log(to)
  // 判断时候为登录的path
  if (to.name === 'Login') {
    next()
  } else {
    // 判断是否登录过
    if (mytoken) {
      next()
    } else {
      next({path: '/login'})
    }
  }
})
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
